
    var form = layui.form, table = layui.table, $ = layui.jquery,id = getQueryVariable("id");

    //产品明细数据
    let detailList = [];
    //附件明细数据
    let annexList = [];
    //操作日志数据
    let operationLog = [];
    layer.ready(function () {
        //获取详情信息
        $.ajax({
            url:"sellOutStock/detail?id="+id,
            success:function(res){
                if(res.status == 200){
                    //主表信息赋值
                    if(null != res.data){
                        //主表数据
                        let vo =  res.data;
                        form.val("editor-form", {
                            "billNo" : vo.billNo,
                            "time" : vo.time,
                            "carryPlanNo" : vo.carryPlanNo,
                            "customerName" : vo.customerName,
                            "contactPerson" : vo.contactPerson,
                            "contactPersonPhone" : vo.contactPersonPhone,
                            "contactPersonAddress" : vo.contactPersonAddress,
                            "outPerson" : vo.outPerson,
                            "operation" : vo.operation,
                            "pickUpDate" : vo.pickUpDate,
                            "memo" : vo.memo
                        });

                        //产品明细数据
                        if(null != res.data.detailList && res.data.detailList.length > 0){
                            detailList = res.data.detailList;
                            table.reload('storageproductstableid',{data : detailList});
                        }

                        //附件
                        if(null != res.data.annexList && res.data.annexList.length > 0){
                            annexList = res.data.annexList;
                            table.reload('attachmenttableid',{data : annexList});
                        }

                    }
                    return false;
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
    })

    $('#editor-form').find('input,textarea,select').attr('disabled',true);
    //--入库产品信息
    table.render({
        elem: '#storageproducts',
        id: 'storageproductstableid',
        data: detailList,
        toolbar: '#storageproductstoolbar',
        cols: [[
            {field: 'numbers',width: 50,type:'numbers',title:'序号'},
            {field: 'lotNo', width: 120, title: '批次号', sort: true},
            {field: 'saleContractNo', width: 120, title: '销售合同号', sort: true},
            {field: 'productCode', width: 120, title: '产品编码', sort: true},
            {field: 'specificationCode', width: 120, title: '规格编码', sort: true},
            {field: 'productUnitName', width: 120, title: '产品单位', sort: true},
            {field: 'outStockQuantity', width: 120, title: '出库数量'},
            {field: 'fcUnitPrice', width: 120, title: '销售单价'},
            {field: 'costSubtotal', width: 120, title: '成本小计'},
            {field: 'moneySubtotal', width: 120, title: '金额小计'},
            {field: 'outStockCost', width: 120, title: '出库成本'},
            {field: 'currency', width: 80, title: '币种'},
            {field: 'shareCostPrice', width: 160, title: '分摊费用单价'},
            {field: 'trayNumber', width: 120, title: '托盘入数', sort: true},
            {field: 'totalTray', width: 120, title: '总托盘', sort: true},
            {field: 'instoreBillNo', width: 120, title: '入库单号', sort: true},
            {field: 'clientProductNo', width: 120, title: '客户货号', sort: true},
            {field: 'color', width: 120, title: '颜色', sort: true},
            {field: 'productCname', width: 120, title: '中文名称', sort: true},
            {field: 'productEname', width: 120, title: '英文名称', sort: true},
            {field: 'productCdesc', width: 120, title: '中文描述', sort: true},
            {field: 'productEdesc', width: 120, title: '英文描述', sort: true},
            {field: 'specificationExplanation', width: 120, title: '规格说明', sort: true},
            {field: 'grossWeight', width: 120, title: '毛重', sort: true},
            {field: 'grossWeightSubtotal', width: 120, title: '毛重小计', sort: true},
            {field: 'netWeight', width: 120, title: '净重', sort: true},
            {field: 'netWeightSubtotal', width: 120, title: '净重小计', sort: true},
            {field: 'bulk', width: 120, title: '体积', sort: true},
            {field: 'bulkSubtotal', width: 120, title: '体积小计', sort: true},
            {field: 'boxAmount', width: 80, title: '箱数', sort: true},
            {field: 'everyBoxAmount', width: 120, title: '每箱数量', sort: true},
            {field: 'clientContractNo', width: 120, title: '客户合同号', sort: true}
        ]],
        page: false,
        limit: Number.MAX_VALUE,
        height: 380
    });

    //---附件
    table.render({
        elem: '#attachment'
        , data: annexList
        , toolbar: '#attachmenttoolbar'
        , cols: [[
            {field: 'fileName', title: '文件名', fixed: true}
            , {field: 'uploadTime', title: '上传日期', fixed: true}
            , {fixed: 'right', width: 180, align: 'center', toolbar: '#attachmenteditor', title: '操作'}
        ]]
        , id: 'attachmenttableid'
        , height: 380
        , page: true
    });

    table.on('tool(attachmenttable)', function (obj) {
        let data = obj.data;
        if (obj.event === 'download') { //下载
            let xmlHttpRequest = new XMLHttpRequest();
            let url = "wjinfo/downloadfile2?filename=" + data.filePath;
            xmlHttpRequest.open('GET', url, true);
            //设置请求头
            xmlHttpRequest.setRequestHeader("Content-type", "application/json")
            xmlHttpRequest.responseType = "blob";
            xmlHttpRequest.send(null);

            xmlHttpRequest.onload = function() {
                let content = xmlHttpRequest.response;
                // 组装a标签
                let elink = document.createElement("a");

                //设置文件下载路径
                elink.download = decodeURIComponent(data.fileName);
                elink.style.display = "none";
                let blob = new Blob([content], { type: 'application/force-download' });

                //解决下载不存在文件的问题，根据blob大小判断
                if(blob.size==0){
                    layer.msg('服务器没找到此文件，请联系管理员!');
                }else{
                    elink.href = window.URL.createObjectURL(blob);
                    document.body.appendChild(elink);
                    elink.click();
                    document.body.removeChild(elink);
                }

            }
        }
    });

    //---操作日志
    table.render({
        elem: '#otherwarehouselog'
        , data: operationLog
        , cols: [[
            {field: 'operationtype', title: '操作类型', fixed: true}
            , {field: 'theoperator', title: '操作员'}
            , {field: 'operationdate', title: '操作日期'}
            , {field: 'modifythecontent', title: '修改内容'}
        ]]
        , id: 'logtableid'
        , height: 380
        , limit: 30//显示的数量
        , page: true
    });